home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW etc / MPW-PR / MPW / Scripts / MakePPCCodeRsrc < prev    next >
Encoding:
Text File  |  1998-11-24  |  5.4 KB  |  194 lines  |  [TEXT/MPS ]

  1. # MakePPCCodeRsrc - Create a PowerPC code resource from a PEF file.
  2. #
  3. # Copyright © 1998, Apple Computer, Inc., All Rights Reserved
  4. #
  5. #    History:
  6. #
  7. #        11/10/98   cae   v1.0d1   Initial version
  8. #        11/24/98   cae   v1.0d2   Added "Set Echo 0" at start of script
  9. #
  10. #    Usage:
  11. #
  12. #        MakePPCCodeRsrc inputfile -rt restype=id [-rn resname] [-ra attributes] [-o outputfile] [-a[ppend]] [-ov] [-rawpef] [-c creator] [-t filetype]
  13. #            inputfile        # a file containing a single PowerPC PEF container in the data fork
  14. #            -rt restype=id    # specify the resource type and ID
  15. #            -rn resname        # specify the resource name
  16. #            -ra attributes    # specify the resource attributes
  17. #            -o outputfile    # specify the output file (default: <inputfilename>.rsrc)
  18. #            -a[ppend]        # append the resource to the output file
  19. #            -ov                # ok to overwrite protected resource when appending
  20. #            -rawpef            # don't add a resource descriptor
  21. #            -c creator        # set the output file creator
  22. #            -t filetype        # set the output file type
  23. #
  24.  
  25. Set Echo 0
  26.  
  27. Set Syntax "inputfile -rt restype=id [-rn resname] [-ra attributes] [-o outputfile] [-a[ppend]] [-ov] [-rawpef] [-c creator] [-t filetype]"
  28.  
  29. Set Error 0
  30.  
  31. Set Cmd "{0}"
  32. Set InputFile ""
  33. Set OutputFile ""
  34. Set ResType ""
  35. Set ResID ""
  36. Set ResName ""
  37. Set ResAttr 0
  38. Set CreatorOpt ""
  39. Set FileTypeOpt ""
  40. Set AppendOpt ""
  41. Set OverwriteOpt ""
  42. Set DoRawPEF 0
  43.  
  44. # Parse the command line.
  45. loop
  46.     break if "{#}" < 1
  47.  
  48.     # Check for the -rt option.
  49.     If "{1}" == "-rt"
  50.         (Evaluate "{2}" =~ /(≈)®1=(≈)®2/) >Dev:Null
  51.         Set ResType "{®1}"
  52.         Set ResID "{®2}"
  53.         shift
  54.     
  55.     # Check for the -rn option.
  56.     Else If "{1}" == "-rn"
  57.         Set ResName "{2}"
  58.         shift
  59.     
  60.     # Check for the -ra option.
  61.     Else If "{1}" == "-ra"
  62.         Set ResAttr "{2}"
  63.         shift
  64.     
  65.     # Check for the -o option.
  66.     Else If "{1}" == "-o"
  67.         Set OutputFile "{2}"
  68.         shift
  69.     
  70.     # Check for the -a[ppend] option.
  71.     Else If "{1}" == "-a" || "{1}" == "-append"
  72.         Set AppendOpt "-a"
  73.     
  74.     # Check for the -ov option.
  75.     Else If "{1}" == "-ov"
  76.         Set OverwriteOpt "-ov"
  77.     
  78.     # Check for the -rawpef option.
  79.     Else If "{1}" == "-rawpef"
  80.         Set DoRawPEF 1
  81.     
  82.     # Check for the -c option.
  83.     Else If "{1}" == "-c"
  84.         Set CreatorOpt "-c ∂"'{2}'∂""
  85.         shift
  86.     
  87.     # Check for the -t option.
  88.     Else If "{1}" == "-t"
  89.         Set FileTypeOpt "-t ∂"'{2}'∂""
  90.         shift
  91.     
  92.     # Found an unknown option.
  93.     Else If "{1}" =~ /-≈/ || "{1}" == -
  94.         Echo "### {Cmd} - ∂"{1}∂" is not an option."
  95.         Set Error 1
  96.     
  97.     # Found the input file.
  98.     Else
  99.         If "{InputFile}" == ""
  100.             Set InputFile "{1}"
  101.         Else
  102.             Echo "### {Cmd} - More than one input file specified."
  103.             Set Error 1
  104.         End
  105.     End
  106.  
  107.     shift
  108. End > Dev:StdErr
  109.  
  110. # Make sure an input file was specified.
  111. If "{InputFile}" == ""
  112.     Echo "### {Cmd} - No input file specified."
  113.     Set Error 1
  114. End > Dev:StdErr
  115.  
  116. # Make sure -rt was specified.
  117. If ("{ResType}" == "" || "{ResID}" == "")
  118.     Echo "### {Cmd} - Must specify a resource type and ID using the -rt option."
  119.     Set Error 1
  120. End > Dev:StdErr
  121.  
  122. # Were there any syntax errors?
  123. If {Error}                                            
  124.     Echo "# Usage - {Cmd} {Syntax}"
  125.     Exit {Error}                                    
  126. End > Dev:StdErr
  127.  
  128. # If -o wasn't specified, use the default output file name.
  129. If "{OutputFile}" == ""
  130.     Set OutputFile "{InputFile}".rsrc
  131. End
  132.  
  133. Set Exit 0
  134.  
  135. # Make sure the output file name isn't too long.
  136. Unset {®1}
  137. (Evaluate "{OutputFile}" =~ /(≈:)*(≈)®1/) ∑ Dev:Null
  138. Set TempCount `Echo -n "{®1}" | Count -c`
  139. If {TempCount} > 31
  140.     Echo "# {0} -  Output file name “{OutputFile}” is too long."
  141.     Exit 2
  142. End > Dev:StdErr
  143.  
  144. # Make sure the input file is a valid PEF file.
  145. DumpPEF "{InputFile}" -c ∑ Dev:Null
  146. If {status} != 0
  147.     Echo "# {0} - “{InputFile}” doesn't appear to be a valid PEF file."
  148.     Exit 2
  149. End > Dev:StdErr
  150.  
  151. # Dump the input file's 'cfrg' resource.
  152. DumpPEF "{InputFile}" -do r > "{TempFolder}MakePPCCodeRsrc_Temp"
  153.  
  154. # Make sure there is a single PEF Container in the data fork of the input file.
  155. Set TempCount `StreamEdit "{TempFolder}MakePPCCodeRsrc_Temp" -d -e '/kOnDiskFlat/ Print' | Count -l`
  156. If {TempCount} == 0
  157.     Echo "# {0} - No PEF Containers found in the data fork of “{InputFile}”."
  158.     Delete -i "{TempFolder}MakePPCCodeRsrc_Temp"
  159.     Exit 2
  160. Else If {TempCount} != 1
  161.     Echo "# {0} - More than one PEF Container found in the data fork of “{InputFile}”."
  162.     Delete -i "{TempFolder}MakePPCCodeRsrc_Temp"
  163.     Exit 2
  164. End > Dev:StdErr
  165.  
  166. # Make sure the PEF Container is a PowerPC container.
  167. Set TempCount `StreamEdit "{TempFolder}MakePPCCodeRsrc_Temp" -d -e '/kPowerPC/ Print' | Count -l`
  168. If {TempCount} != 1
  169.     Echo "# {0} -  No PowerPC PEF Containers found in the data fork of “{InputFile}”."
  170.     Delete -i "{TempFolder}MakePPCCodeRsrc_Temp"
  171.     Exit 2
  172. End > Dev:StdErr
  173.  
  174. # Create the code resource.
  175. If {DoRawPEF}
  176.     # Write the PEF container out to the specified resource.
  177.     Echo "read '{ResType}' ({ResID},∂"{ResName}∂",{ResAttr}) ∂"{InputFile}∂";" | Rez -o "{OutputFile}" {AppendOpt} {OverwriteOpt} {CreatorOpt} {FileTypeOpt}
  178. Else
  179.     # Write a routine descriptor followed by the PEF container out to the specified resource.
  180.     Echo "#include ∂"MixedMode.r∂"" > "{TempFolder}MakePPCCodeRsrc_Temp"
  181.     Echo "type '{ResType}' as 'rdes';" >> "{TempFolder}MakePPCCodeRsrc_Temp"
  182.     Echo "resource '{ResType}' ({ResID},∂"{ResName}∂",{ResAttr}) ∂{" >> "{TempFolder}MakePPCCodeRsrc_Temp"
  183.     Echo "1," >> "{TempFolder}MakePPCCodeRsrc_Temp"
  184.     Echo "$$Read (∂"{InputFile}∂")" >> "{TempFolder}MakePPCCodeRsrc_Temp"
  185.     Echo "∂};" >> "{TempFolder}MakePPCCodeRsrc_Temp"
  186.     Rez "{TempFolder}MakePPCCodeRsrc_Temp" -s ":" -o "{OutputFile}" {AppendOpt} {OverwriteOpt} {CreatorOpt} {FileTypeOpt}
  187. End
  188.  
  189. # Delete the temp file.
  190. Delete -i "{TempFolder}MakePPCCodeRsrc_Temp"
  191.  
  192. Exit {Status}
  193.  
  194.